package xiaoyang.controller.back;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import xiaoyang.Constants;
import xiaoyang.pojo.Dev_user;
import xiaoyang.service.Dev_userService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class devLogin {
    @Resource
    private Dev_userService devUserService;
@RequestMapping("/devLogout")
public String deblogout(HttpSession session){
    session.invalidate();
    return "index";
}
    @RequestMapping("/todevLogin")
    public String toLogin(){
        return "devLogin";
    }
      @RequestMapping("loginDev")
    public String loginDev(@RequestParam String devCode, @RequestParam String devPassword, HttpSession session){
        Dev_user dev_user = devUserService.loginDev(devCode, devPassword);
        if (dev_user!=null){
            session.setAttribute(Constants.DEV_USER_SESSION,dev_user);
            return "devIndex";
        }else {
            throw new RuntimeException("账号或者密码不正确");
            /*return "/devLogin";*/
        }
    }
    @RequestMapping("/index")
    public Object index(){
        return "index";
    }
}
